package com.ruoyi.common.rabbitmq.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

/**
 * MrPing
 */
@Configuration
public class RabbitMqOrderTTLConfig {

    @Bean
    public DirectExchange OrderDirectExchange(){
        return new DirectExchange("yuanju.order.direct.exchange",true,true);
    }

    @Bean
    public Queue orderQueue(){
        Map<String, Object> args = new HashMap<>();
        args.put("x-message-ttl", 1800000);
        args.put("x-dead-letter-exchange","yuanju.dead.order.direct.exchange");
        args.put("x-dead-letter-routing-key","dead");
        return new Queue("yuanju.order.direct.queue",true,false,false, args);
    }

    @Bean
    public Binding orderBinding(){
        return BindingBuilder.bind(orderQueue()).to(OrderDirectExchange()).with("order");
    }
}
